"""Build blob I/O"""
import os
import daos_build

def scons():
    """Execute build"""
    Import('env', 'base_env', 'prereqs', 'control_tgts')

    base_env.AppendUnique(LIBPATH=[Dir('.')])

    env.AppendUnique(LIBPATH=[Dir('.')])
    env.AppendUnique(LIBPATH=[Dir('smd')])

    if not prereqs.server_requested():
        return

    denv = env.Clone()
    denv.AppendUnique(LINKFLAGS=["-Wl,--no-as-needed"])
    denv.Append(CPPDEFINES=['-DDAOS_PMEM_BUILD'])
    prereqs.require(denv, 'pmdk', 'spdk', 'argobots', 'protobufc', 'hwloc')

    SConscript('smd/SConscript')
    denv.AppendUnique(LIBPATH=['smd'])
    denv.AppendUnique(OBJPREFIX='b_')

    # SPDK related libs
    libs = ['spdk_log', 'spdk_env_dpdk', 'spdk_thread', 'spdk_bdev', 'rte_mempool']
    libs += ['rte_mempool_ring', 'rte_bus_pci', 'rte_pci', 'rte_ring']
    libs += ['rte_mbuf', 'rte_eal', 'rte_kvargs', 'spdk_bdev_aio']
    libs += ['spdk_bdev_nvme', 'spdk_blob', 'spdk_nvme', 'spdk_util']
    libs += ['spdk_json', 'spdk_jsonrpc', 'spdk_rpc', 'spdk_trace']
    libs += ['spdk_sock', 'spdk_log', 'spdk_notify', 'spdk_blob_bdev']
    libs += ['spdk_vmd', 'spdk_event_bdev', 'spdk_init']

    # Other libs
    libs += ['numa', 'dl', 'smd']

    tgts = Glob('*.c') + control_tgts
    bio = daos_build.library(denv, "bio", tgts, install_off="../..", LIBS=libs)
    denv.Install('$PREFIX/lib64/daos_srv', bio)

if __name__ == "SCons.Script":
    scons()
